package com.leyou.common.advice;

import com.leyou.common.exception.ExceptionResult;
import com.leyou.common.exception.LyException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice //默认拦截所有的controller
public class BaseExceptionAdvice {
    //声明需要处理的异常类型  如果是自定义的需要再加入新方法
//    @ExceptionHandler(RuntimeException.class)
//    public ResponseEntity<String> handleException(RuntimeException e){
//        return ResponseEntity.status(400).body(e.getMessage());
//    }

    @ExceptionHandler(LyException.class)
    public ResponseEntity<ExceptionResult> handleRuntimeException(LyException e){
        return ResponseEntity.status(e.getStatus()).body(new ExceptionResult(e));
    }

}
